package com.zzty.train.pjm.controller;

import com.zzty.train.pjm.entity.Group;
import com.zzty.train.pjm.entity.User;
import com.zzty.train.pjm.service.GroupingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/grouping")
public class GroupingController {

    @Autowired
    GroupingService groupingService;
    @RequestMapping("/getUser")
    public List<User> getUser(User user){
        List<User>users=groupingService.getUserByClazzId(user);
        return users;
    }

    @RequestMapping("/addTeam")
    public Integer addTeam(Group group){
        Integer count=1;
        Integer count1=0;
        List<Group>groups=groupingService.groupp(group);
        for(int i = 0;i<groups.size();i++){
            if(group.getUserName1().equals(groups.get(i).getUserName1())||group.getUserName1().equals(groups.get(i).getUserName2())
                    ||group.getUserName2().equals(groups.get(i).getUserName1())||group.getUserName2().equals(groups.get(i).getUserName2())
                    ){
                count=0;
            }
        }
        System.out.println("group============="+group.toString());
        System.out.println("groups============="+groups.toString());
        System.out.println("count=============="+count);
        if(count==1){
            count1=groupingService.addTeam(group);//插入分组
        }
        System.out.println("count"+count1);
        return count;
    }

    @RequestMapping("/groupUser")
    public List<Group> groupUser(Group group){
        System.out.println("11"+group.toString());
        List<Group>groups=groupingService.group(group);
        System.out.println("count"+groups.toString());
        return groups;
    }

    @RequestMapping("/deleteGroup")
    public Integer group(Group group){
        System.out.println("11"+group.toString());
        Integer count=groupingService.deleteGroup(group);
        System.out.println("count"+count);
        return count;
    }
}
